home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-tasabo.adb < prev    next >
Text File  |  1996-01-30  |  6KB  |  169 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                         --
  3. --                GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                         --
  5. --              S Y S T E M . T A S K I N G . A B O R T I O N              --
  6. --                                                                         --
  7. --                                 B o d y                                 --
  8. --                                                                         --
  9. --                            $Revision: 1.12 $                             --
  10. --                                                                         --
  11. --       Copyright (c) 1991,1992,1993,1994, FSU, All Rights Reserved        --
  12. --                                                                          --
  13. -- GNARL is free software; you can redistribute it  and/or modify it  under --
  14. -- terms  of  the  GNU  Library General Public License  as published by the --
  15. -- Free Software  Foundation;  either version 2, or (at  your  option)  any --
  16. -- later  version.  GNARL is distributed  in the hope that  it will be use- --
  17. -- ful, but but WITHOUT ANY WARRANTY;  without even the implied warranty of --
  18. -- MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Gen- --
  19. -- eral Library Public License  for more details.  You should have received --
  20. -- a  copy of the GNU Library General Public License along with GNARL;  see --
  21. -- file COPYING.LIB.  If not,  write to the  Free Software Foundation,  675 --
  22. -- Mass Ave, Cambridge, MA 02139, USA.                                      --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with System.Tasking.Utilities;
  27. --  Used for, Utilities.ID_To_ATCB,
  28. --            Utilities.ATCB_To_ID,
  29. --            Utilities.ATCB_Ptr,
  30. --            Utilities.Terminated,
  31. --            Utilities.Not_Accepting,
  32. --            Utilities.All_Tasks_L,
  33. --            Utilities.All_Tasks_List
  34. --            Utilities.Abort_To_Level,
  35. --            Utilities.Abort_Dependents
  36.  
  37. with System.Task_Primitives; use System.Task_Primitives;
  38.  
  39. package body System.Tasking.Abortion is
  40.  
  41.    function ID_To_ATCB (ID : Task_ID) return Utilities.ATCB_Ptr
  42.      renames Utilities.ID_To_ATCB;
  43.  
  44.    function ATCB_To_ID (Ptr : Utilities.ATCB_Ptr) return Task_ID
  45.      renames Utilities.ATCB_To_ID;
  46.  
  47.    function "=" (L, R : Utilities.Task_Stage) return Boolean
  48.      renames Utilities."=";
  49.  
  50.    function "=" (L, R : Utilities.ATCB_Ptr) return Boolean
  51.      renames Utilities."=";
  52.  
  53.    function "=" (L, R : Utilities.Accepting_State) return Boolean
  54.      renames Utilities."=";
  55.  
  56.    --------------------------
  57.    -- Change_Base_Priority --
  58.    --------------------------
  59.  
  60.    procedure Change_Base_Priority (T : Utilities.ATCB_Ptr) is
  61.  
  62.    begin
  63.       --  check for ceiling violations ???
  64.       T.Pending_Priority_Change := False;
  65.       T.Base_Priority := T.New_Base_Priority;
  66.       T.Current_Priority := T.Base_Priority;
  67.       Set_Priority (T.LL_TCB'Access, T. Current_Priority);
  68.    end Change_Base_Priority;
  69.  
  70.    --------------------
  71.    -- Defer_Abortion --
  72.    --------------------
  73.  
  74.    procedure Defer_Abortion is
  75.       T : Utilities.ATCB_Ptr := ID_To_ATCB (Self);
  76.  
  77.    begin
  78.       T.Deferral_Level := T.Deferral_Level + 1;
  79.    end Defer_Abortion;
  80.  
  81.    ----------------------
  82.    -- Undefer_Abortion --
  83.    ----------------------
  84.  
  85.    --  Precondition : Self does not hold any locks!
  86.  
  87.    --  Undefer_Abortion is called on any abortion completion point (aka.
  88.    --  synchonization point). It performs the following actions if they
  89.    --  are pending: (1) change the base priority, (2) abort the task.
  90.    --  The priority change has to occur before abortion. Otherwise, it would
  91.    --  take effect no earlier than the next abortion completion point.
  92.    --  This version of Undefer_Abortion redefers abortion if abortion is
  93.    --  in progress.  There has been some discussion of having
  94.    --  the raise statement defer abortion to prevent abortion of
  95.    --  handlers performing required completion.  This would make
  96.    --  the explicit deferral unnecessary. ???
  97.  
  98.    procedure Undefer_Abortion is
  99.       T : Utilities.ATCB_Ptr := ID_To_ATCB (Self);
  100.       Error : Boolean;
  101.  
  102.    begin
  103.       T.Deferral_Level := T.Deferral_Level - 1;
  104.  
  105.       if T.Deferral_Level = ATC_Level'First and then T.Pending_Action then
  106.          Write_Lock (T.L, Error);
  107.          T.Pending_Action := False;
  108.  
  109.          if T.Pending_Priority_Change then
  110.             Change_Base_Priority (T);
  111.          end if;
  112.  
  113.          Unlock (T.L);
  114.  
  115.          if T.Pending_ATC_Level < T.ATC_Nesting_Level then
  116.             T.Deferral_Level := T.Deferral_Level + 1;
  117.             raise Standard'Abort_Signal;
  118.          end if;
  119.       end if;
  120.  
  121.    end Undefer_Abortion;
  122.  
  123.    -----------------
  124.    -- Abort_Tasks --
  125.    -----------------
  126.  
  127.    --  Called to initiate abortion, however, the actual abortion
  128.    --  is done by abortee by means of Abort_Handler
  129.  
  130.    procedure Abort_Tasks (Tasks : Task_List) is
  131.       Abortee               : Utilities.ATCB_Ptr;
  132.       Aborter               : Utilities.ATCB_Ptr;
  133.       Activator             : Utilities.ATCB_Ptr;
  134.       TAS_Result            : Boolean;
  135.       Old_Pending_ATC_Level : ATC_Level_Base;
  136.  
  137.    begin
  138.       Defer_Abortion;
  139.  
  140.       --  Begin non-abortable section
  141.  
  142.       Aborter := ID_To_ATCB (Self);
  143.  
  144.       for J in Tasks'Range loop
  145.  
  146.          Abortee := ID_To_ATCB (Tasks (J));
  147.  
  148.          if Abortee.Stage = Utilities.Created then
  149.             Utilities.Complete (ATCB_To_ID (Abortee));
  150.             Abortee.Stage := Utilities.Terminated;
  151.             --  Task aborted before activation is safe to complete
  152.             --  Mark This task to be terminated.
  153.          else
  154.             Abortee.Accepting := Utilities.Not_Accepting;
  155.             Utilities.Complete_on_Sync_Point (ATCB_To_ID (Abortee));
  156.             Utilities.Abort_To_Level (ATCB_To_ID (Abortee), 0);
  157.             --  Process abortion of child tasks
  158.             Utilities.Abort_Dependents (ATCB_To_ID (Abortee));
  159.          end if;
  160.  
  161.       end loop;
  162.  
  163.       --  End non-abortable section
  164.  
  165.       Undefer_Abortion;
  166.    end Abort_Tasks;
  167.  
  168. end System.Tasking.Abortion;
  169.